﻿using System;
using System.Reflection;
using System.Collections.Generic;

namespace Flagwind.Plugins.Parsers
{
	public class StaticParser : Parser
	{
		public override object Parse(ParserContext context)
		{
			if(string.IsNullOrWhiteSpace(context.Text) || string.Equals(context.Text, "null", StringComparison.OrdinalIgnoreCase))
			{
				return null;
			}

			var member = PluginUtility.GetStaticMember(context.Text);

			if(member != null)
			{
				switch(member.MemberType)
				{
					case (MemberTypes.Field):
						return ((FieldInfo)member).GetValue(null);
					case (MemberTypes.Property):
						return ((PropertyInfo)member).GetValue(null, null);
				}
			}

			return null;
		}
	}
}